﻿namespace HCRS.Implementation
{
    using HCRS.DataType;
    using System;
    using System.Data;

    /// <summary>
    /// 酒店网站预订引擎管理
    /// </summary>
    public class CRMHotelDomainManager
    {
        /// <summary>
        /// 删除酒店网站预订引擎管理
        /// </summary>
        /// <param name="HotelDomain">HotelDomain(必须设置property_id及languagetype)</param>
        /// <returns>是否成功删除</returns>
        public static bool Delete(CRMHotelDomain HotelDomain)
        {
            return CommonDataAccess.ExecDeleteSQL("CRM_hotelweb_domain", "property_id,languagetype", "int,int", new object[] { HotelDomain.property_id, HotelDomain.languagetype });
        }

        /// <summary>
        /// 获取酒店网站预订引擎对象
        /// </summary>
        /// <param name="HotelDomain">酒店网站预订引擎对象(必须设置property_id及languagetype)</param>
        /// <returns>酒店网站预订引擎对象</returns>
        public static CRMHotelDomain GetCRMHotelDomain(CRMHotelDomain HotelDomain)
        {
            DataTable table = CommonDataAccess.GetTable(string.Concat(new object[] { "select * from CRM_hotelweb_domain where languagetype=", HotelDomain.languagetype, " and property_id=", HotelDomain.property_id, " " }), "HotelDomain");
            if ((table == null) || (table.Rows.Count != 1))
            {
                return null;
            }
            HotelDomain.id = (int) table.Rows[0]["id"];
            HotelDomain.property_id = (int) table.Rows[0]["property_id"];
            HotelDomain.languagetype = (int) table.Rows[0]["languagetype"];
            HotelDomain.webdomain = table.Rows[0]["webdomain"].ToString();
            HotelDomain.noscroll = (int) table.Rows[0]["noscroll"];
            HotelDomain.RateCode = table.Rows[0]["RateCode"].ToString();
            HotelDomain.css = table.Rows[0]["css"].ToString();
            HotelDomain.sloganResv = table.Rows[0]["sloganResv"].ToString();
            HotelDomain.sloganMod = table.Rows[0]["sloganMod"].ToString();
            HotelDomain.sloganCxl = table.Rows[0]["sloganCxl"].ToString();
            HotelDomain.sloganNewResv = table.Rows[0]["sloganNewResv"].ToString();
            HotelDomain.EmailFrom = table.Rows[0]["EmailFrom"].ToString();
            HotelDomain.EmailAlias = table.Rows[0]["EmailAlias"].ToString();
            HotelDomain.EmailTitle = table.Rows[0]["EmailTitle"].ToString();
            return HotelDomain;
        }

        /// <summary>
        /// 添加酒店网站预订相关信息
        /// </summary>
        /// <param name="HotelDomain"></param>
        /// <returns></returns>
        public static bool Insert(CRMHotelDomain HotelDomain)
        {
            if (IsExist(HotelDomain))
            {
                return false;
            }
            return CommonDataAccess.ExecInsertSQL("CRM_hotelweb_domain", "property_id,languagetype,webdomain,noscroll,RateCode,css,sloganResv,sloganMod,sloganCxl,sloganNewResv,EmailFrom,EmailAlias,EmailTitle", "int,int,varchar,int,varchar,varchar,nvarchar,nvarchar,nvarchar,nvarchar,varchar,varchar,nvarchar", new object[] { HotelDomain.property_id, HotelDomain.languagetype, HotelDomain.webdomain, HotelDomain.noscroll, HotelDomain.RateCode, HotelDomain.css, HotelDomain.sloganResv, HotelDomain.sloganMod, HotelDomain.sloganCxl, HotelDomain.sloganNewResv, HotelDomain.EmailFrom, HotelDomain.EmailAlias, HotelDomain.EmailTitle });
        }

        /// <summary>
        /// 酒店网站预订引擎是否存在
        /// </summary>
        /// <param name="HotelDomain">酒店网站预订引擎对象</param>
        /// <returns></returns>
        public static bool IsExist(CRMHotelDomain HotelDomain)
        {
            DataTable table = CommonDataAccess.GetTable(string.Concat(new object[] { "select * from CRM_hotelweb_domain where languagetype=", HotelDomain.languagetype, " and property_id=", HotelDomain.property_id, " " }), "HotelDomain");
            if ((table != null) && (table.Rows.Count == 0))
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 更新酒店网站预订相关信息
        /// </summary>
        /// <param name="HotelDomain"></param>
        /// <returns></returns>
        public static bool Update(CRMHotelDomain HotelDomain)
        {
            return CommonDataAccess.ExecUpdateSQL("CRM_hotelweb_domain", "webdomain,noscroll,RateCode,css,sloganResv,sloganMod,sloganCxl,sloganNewResv,EmailFrom,EmailAlias,EmailTitle", "varchar,int,varchar,varchar,nvarchar,nvarchar,nvarchar,nvarchar,varchar,varchar,nvarchar", new object[] { HotelDomain.webdomain, HotelDomain.noscroll, HotelDomain.RateCode, HotelDomain.css, HotelDomain.sloganResv, HotelDomain.sloganMod, HotelDomain.sloganCxl, HotelDomain.sloganNewResv, HotelDomain.EmailFrom, HotelDomain.EmailAlias, HotelDomain.EmailTitle }, "property_id,languagetype", "int,int", new object[] { HotelDomain.property_id, HotelDomain.languagetype });
        }
    }
}

